package cn.fengzhilun.javase.day14.day09;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;

public class TestMap {
	@Test
	public void test() {
		assertEquals("星期一",getWeekDayName(1) );
		assertEquals("星期天", getWeekDayName(7));
		assertNull(getWeekDayName(8));
	}
	
	public static String getWeekDayName(int num) {
//		if(num >7||num<1) {
//			return null;
//		}
//		
//		String []array= {"星期一","星期二","星期三","星期四","星期五","星期六","星期天"};
//		
//		return array[num-1];
		Map<Integer,String> map =new HashMap<>();
		map.put(1, "星期一");
		map.put(2, "星期二");
		map.put(3, "星期三");
		map.put(4,"星期四");
		
		return map.get(num);
	}
	
	@Test
	public void test1() {
		assertEquals( "星期一", getWeekDayName(1));
		assertEquals("星期二", getWeekDayName(2));
		assertNull(getWeekDayName(0));
	}
	public static final Map<Integer,String> MAP=new HashMap<>();
	static {
		MAP.put(1,"星期一" );
		MAP.put(2, "星期二");
		MAP.put(7, "星期天");
	}
	
	public static String getWeekDay(int num) {
		return MAP.get(num);
	}
	@Test
	public void test2() {
		assertEquals("星期天", getWeekDay(7));
	}
	
	@Test
	public void test3() {
		Map<Integer, String> map = new HashMap<>();

		map.put(1, "星期一");
		map.put(2, "星期二");
		map.put(7, "星期天");

		Set<Entry<Integer, String>> elments = map.entrySet();
		
		for(Entry<Integer, String> entry :elments) {
			System.out.println("key:" + entry.getKey() + "value:"+ entry.getValue());
		}
		System.out.println("*******");
		for(Integer key:map.keySet()) {
			System.out.println("key:" + key +"value:" + map.get(key));
		}

//		for (Entry entry : elments) {
//			System.out.println("key: " + entry.getKey() + "value" + entry.getValue());
//		}
		System.out.println("*******");
		for(Integer key:map.keySet()) {
			
			System.out.println("key:" + key +"value:" + map.get(key));
		}
	}
	
	@Test
	public void test4() {
		String s1 ="a b";
		String s2="";
		System.out.println(s2.length());
		
		String[] split =s1.split(" ");
		System.out.println(Arrays.toString(split));
	}
	
	@Test
	public void test5() {
		Map<String,Integer> map = new HashMap<>();
		
		System.out.println("java".hashCode());
		System.out.println("c++".hashCode());
		System.out.println("python".hashCode());
		System.out.println("swift".hashCode());
		
		
	}
}
